package com.example.friendcash.database.dao.implementation.sqlite.android;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.example.friendcash.database.dao.interfaces.IDaoFactory;
import com.example.friendcash.database.dao.interfaces.IGenericDao;

import java.util.List;

class DbHelper extends SQLiteOpenHelper {

    private final IDaoFactory daoFactory;

    DbHelper(Context context, String databaseName, IDaoFactory daoFactory) {
        super(context, databaseName, null, 1);
        this.daoFactory = daoFactory;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        final List<IGenericDao<?>> allGenericDao = daoFactory.createAllGenericDao();
        for (final IGenericDao<?> dao : allGenericDao) {
            dao.createStorage(db);
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

}
